#!/bin/bash
echo "========================================"
echo "Flask数据库初始化脚本"
echo "========================================"
echo

echo "1. 设置环境变量..."
export FLASK_APP=run.py

echo
echo "2. 检查是否已初始化迁移仓库..."
if [ ! -d "migrations" ]; then
    echo "迁移仓库不存在，正在初始化..."
    flask db init
    echo
else
    echo "迁移仓库已存在"
    echo
fi

echo "3. 创建初始迁移..."
flask db migrate -m "Initial migration"
echo

echo "4. 应用迁移到数据库..."
flask db upgrade
echo

echo "========================================"
echo "数据库初始化完成！"
echo "========================================"